[gcode_macro RESPOND]
rename_existing: BASE_RESPOND
gcode:
  {% set colors = ('primary', 'secondary', 'accent', 'info', 'success', 'error', 'warning') %}

  {% if params.PREFIX is defined %}
    {% set prefix = 'PREFIX=' + params.PREFIX|string %}
  {% endif %}

  {% if params.TYPE is defined %}
      {% if params.TYPE in ('echo', 'echo_no_space', 'command', 'error') and params.TYPE != '' %}    
          {% set type = 'TYPE=' + params.TYPE|string %}
      {% else %}
          BASE_RESPOND TYPE=error MSG="RESPOND TYPE '{params.TYPE}' is invalid. Must be one of 'echo', 'command' or 'error'"
      {% endif %}
  {% endif %}
        
  {% if params.MSG is defined %}   
    {% set msg = 'MSG="'+ params.MSG + '"'|string %}
  {% endif %}

  {% if params.COLOR is defined %}
      {% set color = params.COLOR|lower %}

      {% if color in colors %}
          {% set msg = 'MSG="<span class=' + color + '--text>' + params.MSG + '</span>"'|string %}
  
      {% else %}
          BASE_RESPOND TYPE=error MSG="RESPOND COLOR '{color}' is invalid. Must be one of 'primary', 'secondary', 'accent', 'info', 'success', 'warning' or 'error'"
      {% endif %}
       
  {% endif %}
  BASE_RESPOND {prefix} {type} {msg}
############################################################################################
#[gcode_macro BEGIN_LAYER]
#description: Start a new layer and notify system
#gcode:

#  {% set CUR  = params.NUM|default(0)|float + 1 %}
#  {% if params.COUNT and params.COUNT != 0 %}
#        {% set TOTAL = params.COUNT|default(0)|float %}
#  {% elif printer["gcode_macro middle"].total_layer and printer["gcode_macro middle"].total_layer!= 0 %}
#        {% set TOTAL = printer["gcode_macro middle"].total_layer %}
#  {% else %}
#         { action_respond_info("COUNT of Total layers is required!") }
#  {% endif %}

#  SET_GCODE_VARIABLE MACRO=middle VARIABLE=cur_layer VALUE={CUR}
#  SET_GCODE_VARIABLE MACRO=middle VARIABLE=total_layer VALUE={TOTAL}
 # {action_respond_info("BEGIN CUR: %s TOTAL: %s" % (CUR, TOTAL))}


#[gcode_macro middle]
#description: Variable_storage
#variable_cur_layer: 0
#variable_total_layer: 0
#gcode:
#    {action_respond_info("MIDDLE TOTAL: %s TOTAL: %s" % (CURRENT_LAYER, TOTAL_LAYER))}

#[gcode_macro MATRIX]
#gcode:
#    {% set CURRENT_LAYER = printer["gcode_macro middle"].cur_layer %}
#    {% set TOTAL_LAYER = printer["gcode_macro middle"].total_layer %}

#    {% set angle_move = 180 / TOTAL_LAYER * CURRENT_LAYER %} #задаем переменную сдвига на слой. вот здесь и задаем свою серву 180 или 270 градусов.
#    { action_respond_info("MATIRIX TOTAL: %s CUR: %s" % (TOTAL_LAYER, CURRENT_LAYER)) } #вывод в консоль текущего слоя и всего слоев
#    { action_respond_info("angle %s" % angle_move) } # вывод в консоль текущего угла
#    SET_SERVO SERVO=matrix ANGLE={angle_move} #4 макрос сдвига

; -----------------------------------------------------------------------    
; что вписать в куру в разделе постобработки пункт "найти и заменить" копировать текст внутри скобок()
;(;LAYER_COUNT:(\d.*)\n)
; на что меням
;(;LAYER_COUNT:\1\nBEGIN_LAYER COUNT=\1\n)

; -----------------

;еще раз "найти и заменить" 
;(;LAYER:(\d.*);\n)
; на это
;(;LAYER:\1;\nBEGIN_LAYER NUM=\1\nMATRIX\n)
;-------------------------------------------------------------------------
#[gcode_macro move_cam]
#gcode:
#  {% set T = params.T|default(0) %}
#  SET_SERVO SERVO=matrix ANGLE={T}
##########################################################################################################################################



#[led_effect panel_idle]
#autostart:              true
#frame_rate:             24
#leds:
#    neopixel:my_neopixel (1,5,15,20,27)
#layers:
#   breathing  10 1 top (.5,.5,0), (0.5,.5,0), (0.5,.2,0), (.1,.1,0)
#       static  1 0 bottom (.25,.25,0), (0.25,.1,0), (0.25,.1,0), (.1,.1,0)
#
#[led_effect Heater]
#leds:
#    neopixel:printhead (2)
#autostart:                          true
#frame_rate:                         24
#heater:                             extruder
#layers:
#    heater  60 1 add    (0,2,0.2,0), (0,0.5,0)
#    static  0  1 divide    (0.5,0,0)

#[delayed_gcode welcome]
#initial_duration: 5.
#gcode:
#    QUERY_BME280
#    PartyTime
    
[gcode_macro beep]
gcode:
  SET_PIN PIN=_Zummer VALUE=1
  G4 P5000
  SET_PIN PIN=_Zummer VALUE=0



#[gcode_macro _set_leds]
#gcode:
#    {% if printer.extruder.target == 0 %} 
#        # the extrude heater is off 
#    {% else %}
#        # the extrude heater is on
#        {% if printer.idle_timeout.state == "Printing" %}
#            # we are printing 
#            # progress is in the display_status object 
#            {% set perc = printer.display_status.progress %} 
#            # set this to how many leds you have for your bar 
#            {% set numleds = 27 %}
#            {% set last = (perc|float * numleds|float)|int %}
#            {% for n in range(numleds) %} 
#                {% if n < last %} 
#                    SET_LED LED=my_neopixel RED=0 GREEN=0.25 BLUE=0.0 TRANSMIT=0 index={ n + 1|int }
#                {% else %} 
#                    SET_LED LED=my_neopixel RED=0.25 GREEN=0.25 BLUE=0.25 TRANSMIT=0 index={ n + 1|int }
#                {% endif %}
#            {% endfor %}
#            # now actually transmit it
#            SET_LED LED=my_neopixel RED=0.25 GREEN=0 BLUE=0 TRANSMIT=1 INDEX={ last + 1|int }
#        {% endif %}
#    {% endif %}
#    
#[delayed_gcode _update_leds_loop]
#initial_duration: 5 
#gcode:
#    _set_leds 
#    UPDATE_DELAYED_GCODE ID=_update_leds_loop DURATION=60
